package com.example.toolbar;

import android.os.Bundle;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class testActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_test);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        Toolbar  toolbar=findViewById(R.id.toolbar);
        toolbar.setNavigationOnClickListener(v -> finish());
        toolbar.collapseActionView();
        toolbar.inflateMenu(R.menu.menubar);
        
        toolbar.setOnMenuItemClickListener(item -> {
            if (item.getItemId()==R.id.add)
                {
                    Toast.makeText(testActivity.this,"点击了添加按钮",Toast.LENGTH_SHORT).show();
                    
                }
            else if (item.getItemId()==R.id.delete) {
                Toast.makeText(testActivity.this,"点击了删除按钮",Toast.LENGTH_SHORT).show();
                
                }
            else if (item.getItemId()==R.id.moer) {
                Toast.makeText(testActivity.this,"点击了更多按钮",Toast.LENGTH_SHORT).show();
                
                }


            return true;
        });
    }
}